package com.lintf.distributed.transaction.order.rpc;

import com.lintf.distributed.transaction.api.OrderRPCService;
import com.lintf.distributed.transaction.dto.OrderGetDTO;
import com.lintf.distributed.transaction.order.entity.Order;
import com.lintf.distributed.transaction.order.service.OrderService;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;

import java.util.Objects;

/**
 * @ author lintf
 * @ system Mac
 * @ data 2025/7/9
 * @ package_name com.lintf.distributed.transaction.order.rpc
 * @ project_name distributed-transaction
 * @ desc
 */
@RequiredArgsConstructor
@DubboService(interfaceClass = OrderRPCService.class, version = OrderRPCService.RPC_VERSION)
public class OrderRPCServiceImpl implements OrderRPCService {

    private final OrderService orderService;

    @Override
    public OrderGetDTO getOrderDetails(Long orderId) {
        Order order = orderService.getById(orderId);
        if (Objects.isNull(order)) {
            throw new RuntimeException("Order not found with id: " + orderId);
        }
        OrderGetDTO dto = new OrderGetDTO();
        BeanUtils.copyProperties(order, dto);
        return dto;
    }
}
